package com.spring.validator_test_3;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;
import java.util.List;

@Controller
public class SpringValidatorTest {

	@RequestMapping("/validator/springtest")
	public void  springte(@Valid Person person, BindingResult result){
		if(result.hasErrors()){
			List<ObjectError> list = result.getAllErrors();
			for(ObjectError error: list){
				//System.out.println(error.getObjectName());
				//System.out.println(error.getArguments()[0]);
				System.out.println(error.getDefaultMessage());//验证信息
			}
		}
	}
}